
class Singleton {
    private static Singleton instance = new Singleton();

    public static Singleton getInstance() {
        return instance;
    }

    private Singleton(){}; //阻止后续代码new出新的实例
}

// 懒汉模式实现单例模式
class SingletonLazy {
    // 这个引用指向唯一的实例, 先初始化为null, 而不是立即创建实例
    private static SingletonLazy instance = null;

    public SingletonLazy getInstance() {
        if(instance == null) {
            instance = new SingletonLazy();
        }

        return instance;
    }

    private SingletonLazy() {};
}

public class Test {
    public static void main(String[] args) {

    }
}
